{include file="header.html"}
<style type="text/css">
 .some-width{
 	width: 180px;
 }
 .some-line{
 	display: inline-block;padding-top: 6px; font-size: 15px;padding-left: 5px;
 }
</style>
<script src="/js/ckeditor/ckeditor.js"></script>
<script>
    var i=0;
    $(function(){
        $('#flash').change(function(){
            i++;
            if(i%2) {
                $('#img').css('display','');
            }
            else {
                $('#img').css('display','none');
            }
        });
    });
</script>
<div class="page-header">
	<h6>
		商品管理
		<small>
			<i class="ace-icon fa fa-angle-double-right"></i>
			商品添加
		</small>
	</h6>
</div><!-- /.page-header -->
<div class="row">
<div class="col-xs-12">
	<form class="form-horizontal" role="form" method="post" action="?app=goods&act=edit" enctype="multipart/form-data">
		<input type="hidden" id="goods_id" name="goods_id" value="{$goods->id}" class="col-xs-6" />
		<input type="hidden" id="oldwhere" name="oldwhere" value="{$oldwhere}" class="col-xs-6" />
		<input type="hidden" id="current_page" name="current_page" value="{$current_page}" class="col-xs-6" />
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="name"> 产品名称 </label>
			<div class="col-sm-10">
				<input type="text" id="name" name="name" value="{$goods->name}" class="col-xs-6" />
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="huohao"> 货号 </label>
			<div class="col-sm-10">
				<input type="text" id="huohao" name="huohao" value="{$goods->huohao}" class="col-xs-6 some-width" />
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="default_pic"> 主图片 </label>
			<div class="col-sm-10" style="margin-top:10px">
				<input type="file" id="pic" name="default_pic" value="" />
				<img src="{if $goods->default_pic !== ''}{$goods->default_pic}{else}/images/nopic.png{/if}" style="width:100px;float:left;" />
			</div>
		</div>
		<!-- <div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="memo"> 说明图片 </label>
			<div class="col-sm-10">
				<input type="file" id="memo" name="memo" value="{$goods->memo}" class="col-xs-6" />
				<img src="{$goods->memo}" style="width:100px;">
			</div>
		</div> -->
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="description"> 商品简要描述 </label>
			<div class="col-sm-10">
				<input type="text" id="description" name="description" value="{$goods->description}" class="col-xs-6" />
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="keywords"> 商品关键词 </label>
			<div class="col-sm-10">
				<input type="text" id="keywords" name="keywords" value="{$goods->keywords}" class="col-xs-6 some-width" />
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="weight"> 商品重量 </label>
			<div class="col-sm-10">
				<input type="text" id="weight" name="weight" value="{$goods->weight}" class="col-xs-6 some-width" /><span class="some-line"> kg </span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="size"> 商品体积 </label>
			<div class="col-sm-10">
				<input type="text" id="size" name="size" value="{$goods->size}" class="col-xs-6 some-width" /><span class="some-line"> cm<sup>3</sup></span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="price"> 商品价格 </label>
			<div class="col-sm-10">
				<input type="text" id="price" name="price" value="{$goods->price}" class="col-xs-6 some-width" /><span class="some-line"> 元 （默认规格）</span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="market_price"> 市场价格 </label>
			<div class="col-sm-10">
				<input type="text" id="market_price" name="market_price" value="{$goods->market_price}" class="col-xs-6 some-width" /><span class="some-line"> 元 </span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="cost_price"> 成本价 </label>
			<div class="col-sm-10">
				<input type="text" id="cost_price" name="cost_price" value="{$goods->cost_price}" class="col-xs-6 some-width" /><span class="some-line"> 元 </span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="price_count"> 促销价、特价 </label>
			<div class="col-sm-10">
				<input type="text" id="price_count" name="price_count" value="{$goods->promote_price}" class="col-xs-6 some-width" /><span class="some-line"> 元 （默认规格）</span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="begin_time"> 促销开始日期 </label>
			<div class="col-sm-10">
				<input type="text" id="begin_time" name="begin_time" value="{$goods->promote_begin_time|date_format:'%Y-%m-%d'}" class="col-xs-6 some-width" />
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="end_time"> 促销结束日期 </label>
			<div class="col-sm-10">
				<input type="text" id="end_time" name="end_time" value="{$goods->promote_end_time|date_format:'%Y-%m-%d'}" class="col-xs-6 some-width" />
			</div>
		</div>

		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="cate"> 所属分类 </label>
			<div class="col-sm-2">
				<select name="cate" id="cate" class="form-control some-width">
					<option value="">请选所属分类</option>
					{foreach from = $cate_parent item =val}
						<optgroup label="{$val->name}">
							{foreach from = $cate item =row}
								{if $row->parent_id == $val->id}
								<option value="{$row->id}" {if $goods->category_id == $row->id}selected{/if}>{$row->name}</option>
								{/if}
							{/foreach}
						</optgroup>
					{/foreach}
				</select> 		
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="shop"> 商品所属商店 </label>
			<div class="col-sm-2">
				<select name="shop" id="shop" class="form-control some-width">
					<option value="">请选所属商店</option>
						{foreach from = $shop item =row}
						<option value="{$row->id}"{if $goods->shop_id == $row->id}selected{/if}>{$row->name}</option>
						{/foreach}
				</select> 		
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="brand"> 商品所属品牌 </label>
			<div class="col-sm-2">
				<select name="brand" id="brand" class="form-control some-width">
					<option value="">请选所属品牌</option>
						{foreach from = $brand item =row}
						<option value="{$row->id}"{if $goods->brand_id == $row->id}selected{/if}>{$row->name}</option>
						{/foreach}
				</select> 		
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="stocks"> 库存 </label>
			<div class="col-sm-10">
				<input type="number" id="stocks" name="stocks" value="{$goods->stocks}" class="col-xs-6 some-width" /><span class="some-line">（默认规格）</span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="stocks_dg"> 库存报警数量 </label>
			<div class="col-sm-10">
				<input type="number" id="stocks_dg" name="stocks_dg" value="{$goods->stock_alert_number}" class="col-xs-6 some-width" />
			</div>
		</div>
		<div class="form-group cost" >
			<label class="col-sm-2 control-label no-padding-right" for="fee"> 运费 </label>
			<div class="col-sm-10">
				<input type="number" id="fee" name="fee" value="{$goods->shipping_fee}" class="col-xs-6 some-width" /><span class="some-line"> 元 </span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="free"> 是否包邮 </label>
			<div class="col-sm-10">
				<div class="radio" >
					<label  id="free1">
						<input type="radio" name="free" value="1" class="ace" {if $goods->free_shipping == 1 }checked{/if}  />
						<span class="lbl"> 是</span>
					</label>
				</div>
				<div class="radio">
					<label  id="free2">
						<input type="radio" name="free" value="0" class="ace" {if $goods->free_shipping == 0 }checked{/if}  />
						<span class="lbl"> 否</span>
					</label>
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="integral"> 积分购买 </label>
			<div class="col-sm-10">
				<input type="text" name="integral" id="integral" value="{$goods->integral}" class="col-xs-2 some-width" />
			</div>
		</div>
		<!-- <div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="give_integral"> 购买后赠送积分 </label>
			<div class="col-sm-10">
				<input type="text" name="give_integral" id="give_integral" value="{$goods->give_integral}" class="col-xs-2 some-width" />
			</div>
		</div> -->
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="ext_property"> 扩展属性 </label>
			<div class="col-sm-10">
				<div class="checkbox" >
					<label id="ext_property1">
						<input type="checkbox" name="ext_property[]" id="ext_property1" value="2" class="ace" {if $goods->ext_property == 2 }checked{/if}  />
						<span class="lbl"> 热销</span>
					</label>
				</div>
				<div class="checkbox">
					<label id="ext_property2">
						<input type="checkbox" name="ext_property[]" id="ext_property2" value="5" class="ace" {if $goods->ext_property == 5 }checked{/if}  />
						<span class="lbl"> 折扣</span>
					</label>
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="sort"> 排序 </label>
			<div class="col-sm-10">
				<input type="text" name="sort" id="sort" value="{$goods->sort}" class="col-xs-2 some-width" /><span class="some-line">数字越小，排在越前</span>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="status"> 状态 </label>
			<div class="col-sm-10">
				<div class="radio">
					<label>
						<input type="radio" name="status" value="1" class="ace" {if $goods->status == 1 }checked{/if} />
						<span class="lbl"> 正常</span>
					</label>
				</div>
				<div class="radio">
					<label>
						<input type="radio" name="status" value="0" class="ace" {if $goods->status == 0 }checked{/if}  />
						<span class="lbl"> 下架</span>
					</label>
				</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="in_shop"> 线下门店是否有销售 </label>
			<div class="col-sm-10">
				<div class="radio">
					<label>
						<input type="radio" name="in_shop" value="1" class="ace" {if $goods->in_shop == 1 }checked{/if}/>
						<span class="lbl"> 是</span>
					</label>
				</div>
				<div class="radio">
					<label>
						<input type="radio" name="in_shop" value="0" class="ace" {if $goods->in_shop == 0 }checked{/if}/>
						<span class="lbl"> 否</span>
					</label>
				</div>
			</div>
		</div>

		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="note"> 商家备注 </label>
			<div class="col-sm-10">
				<input type="text" name="note" id="note" value="{$goods->seller_note}" class="col-xs-2 some-width" />
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="content"> 商品详情 <span  style="color: red;">参考图片：790x826</span></label>
			<div class="col-sm-10">
				<textarea class="ckeditor" name="content" id="content" style="width:95%" rows="50">{$goods->content}</textarea>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right" for="pic" style="margin-right: 10px;"> 上传商品相册 </label>
			<div id="imgs" style="float:left;position:relative; " >
			<span style="color: red;">图片：720X960</span>
                {if $pics}
                    {foreach from=$pics item=pic}
                        <div id="{$pic->id}" style='float:left;position:relative;margin-right:10px;'>
                            <input type="hidden" name="pics[]" value="{$pic->pic}">
                            <img src='{$pic->pic}' width='158' style='margin-top:10px;'><br/>
                            <input type='text' name='sort_pic[]' placeholder="排序" value='{$pic->sort}' /><br/>
                            <a href='javascript:void(0)' style='position:absolute;right:-5.5px;top:1.5px;' onclick="onDel({$pic->id});"><img src='/images/horum_img_delete.png' width='20' height='20'></a>
                        </div>
                    {/foreach}
                {/if}
            </div>
            <div id="file">
                <input id="pic_file"  type="file" name="pic_file"  value="" onchange="UploadFile()" style="padding-top:5px;"/>
            </div>
		</div>
		<div class="form-group" >
			<label class="col-sm-2 control-label no-padding-right" for="spec"><span class="btn-info" style="display:inline-block; width:20px;text-align:center;" id="add">+</span> 规格 </label>
			<div class="col-sm-10">
				<table id="simple-table" class="table table-striped table-bordered table-hover">
					<thead>
						<tr>
							<th>规格：</th>
							<th>库存：</th>
							<th>积分：</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="addTr">
						{if $spec}
						{foreach from = $spec item=rr key=k}
						<tr align='center'>
							<td><input type='text' id='spec{$k}' name='spec[]' value='{$rr->spec}'/></td>
							<td><input type='text' id='sto{$k}' name='sto[]' value='{$rr->stocks}' /></td>
							<td><input type='text' id='pri{$k}' name='pri[]' value='{$rr->price}' /></td>
							<td onClick='getDel(this)' id='hid{$k}'><a href='javascript:void(0)'>删除</a></td>
						</tr>
						{/foreach}
						{/if}

					<tbody>
				</table>
			</div>
		</div>

		<div class="clearfix form-actions">
			<div class="col-md-offset-3 col-md-9">
				<button class="btn btn-info" type="submit">
					<i class="ace-icon fa fa-check bigger-110"></i>
					提交
				</button>

				&nbsp; &nbsp; &nbsp;
				<button class="btn" type="reset">
					<i class="ace-icon fa fa-undo bigger-110"></i>
					重置
				</button>
			</div>
		</div>
	</form>
</div>
</div>
<script type="text/javascript">
    //ajax
    var xhr;
    var now=0;
    function createXMLHttpRequest()
    {
        if(window.ActiveXObject)
        {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else if(window.XMLHttpRequest)
        {
            xhr = new XMLHttpRequest();
        }
    }
    function UploadFile()
    {
        if($('#imgs').children().length>=6){
            alert("图片不可超过6张");
        }
        else{
            var fileObj = document.getElementById("pic_file").files[0];
            var FileController = '?app=goods&act=upload_pic';
            var form = new FormData();
            form.append("pic_file", fileObj);
            createXMLHttpRequest();
            xhr.onreadystatechange = handleStateChange;
            xhr.open("post", FileController, true);
            xhr.send(form);
        }
    }

    function handleStateChange()
    {
        if(xhr.readyState == 4)
        {
            if (xhr.status == 200 || xhr.status == 0)
            {
                var result = xhr.responseText;
                document.getElementById("imgs").innerHTML+="<div id='"+now+"' style='float:left;position:relative;margin-right:10px;'>"
                        +"<img src='"+result+"' width='158' style='margin-top:10px;'>"+
                        "<input type='hidden' name='pics[]'  value='"+result+"' /><br>"+
                        "<input type='text' name='sort_pic[]' placeholder='排序' value='999' /><br>"+
                        "<a href='javascript:void(0)' style='position:absolute;right:-5.5px;top:1.5px;' onclick='onDel("+now+");'><img src='/images/horum_img_delete.png' width='20' height='20'></a></div>";
                if($('#imgs').children().length>=6){
                    $('#file').hide();//('display','hidden');
                }
            }
        }
    }
    function onDel(id)
    {
        if(confirm("是否删除？")){
            var picdiv = document.getElementById(id);
            picdiv.parentNode.removeChild(picdiv);
            if($('#imgs').children().length<6){
                $('#file').show();//('display','hidden');
            }
        }else
        {
            return false;
        }
    }
//添加规格
	$(function(){   
    $("#add").click(function(){           
        $str='';
        $str+="<tr align='center'>";
        $str+="<td><input type='text' name='spec[]' id='spec'/></td>";
        $str+="<td><input type='text' name='sto[]' id='sto' /></td>";
        $str+="<td><input type='text' name='pri[]'id='pri' /></td>";
        $str+="<td onClick='getDel(this)'><a href='javascript:void(0)'>删除</a></td>";     
        $str+="</tr>";
        $("#addTr").append($str);    
    });
});
 //删除规格
	function getDel(k){
    	$(k).parent().remove();     
	}
//获取默认值并赋值
	$(function(){
		$("#stocks").blur(function(){
			var a = $(this).val();
			$("#sto0").attr("value", a);
		})
		$("#price").blur(function(){
			var a = $(this).val();
			$("#pri0").attr("value", a);
		})
		$("#price_count").blur(function(){
			var a = $(this).val();
			$("#pro0").attr("value", a);
		})
		$("#sto0").blur(function(){
			var a = $(this).val();
			$("#stocks").attr("value", a);
		})
		$("#pri0").blur(function(){
			var a = $(this).val();
			$("#price").attr("value", a);
		})
		$("#pro0").blur(function(){
			var a = $(this).val();
			$("#price_count").attr("value", a);
		})
		$("#hid0").hide();
	})
</script>
<script>
$(function(){
	$('#free2').click(function(){
		$('.cost').show();
	})
	$('#free1').click(function(){
		$('.cost').hide();
	})
	
})
$(function(){
	$('#begin_time').datepicker({
		useStyle:'datepicker2',
		readonly:false,
		showTime:true,
		showSecond:false,
		format:'yyyy-mm-dd hh:mm'
	});
	$('#end_time').datepicker({
		useStyle:'datepicker2',
		readonly:false,
		showTime:true,
		showSecond:false,
		format:'yyyy-mm-dd hh:mm'
	});
});	
</script>
{include file="footer.html"}